﻿<?php echo $this->Html->css('product'); ?>
<?php echo $this->Html->css('form'); ?>
<?php echo $this->Html->script('ckeditor/ckeditor'); ?>
<?php echo $this->Html->script('modify_image'); ?>
<?php echo $this->Html->script('product_edit'); ?>

<?php
$myControl = $this->params["controller"];
$myAction = $this->params["action"];

$cont = Inflector::classify($myControl);
$act = Inflector::camelize($myAction);
?>
<?php echo $this->Form->create('Product',array('url'=>'/products/edit/'.$id,'id' => "{$cont}{$act}Form",'enctype' => 'multipart/form-data'));?>
						

<? echo $this->Form->hidden('type');
echo $this->Form->hidden('id');?>
<div class="contentMain">
<div class="grayBox">
			
<div class="form_wrapper">
		<h2>Edit Product</h2>
			<ul class="addBox">
				<li>
					<span class="titleName"><label>Name</label></span>
					<? 
					echo $this->Form->text('name');
					echo $this->Form->error('name');
					?>
				</li>
				<li>
					<span class="titleName"><label>Category</label></span>
					<?php
					echo $form->input('category_id', array(
						'options' => $categories,
						'label' => false,
						'div' => false
						));
					?>
				</li>
				<li>
					<span class="titleName"><label>Manufacturer</label></span>
					<?php
					echo $form->input('manufacturer_id', array(
						'options' => $manufacturers,
						'label' => false,
						'div' => false
						));
					?>
				</li>
				<li>
						<span class="titleName"><label>Thumbnail for product</label></span>
						<?php
							echo $this->Form->file('image_form' ,array('class'=>'inputFile', 'onchange' => 'modify_image(this, "showThumbnail1")'));
							echo $this->Form->error('image_form',array('class'=>'error'));							
						?>
						<div class="fontSmall">File type JPG, PNG or GIF only. Maximum of 800kb. Recommended dimension is 210 x 150. </div>
				</li>
				<li>
						<?php
							$image = isset($this->data['Product']['image'])? $this->data['Product']['image'] : '';
							echo $this->Form->hidden('image', array('value'=>$image));
							if ($image) {
								$rId = $id;
								$myPath = "posts/" . $this->data['Product']['image'];
								$imageFile = IMAGES . $myPath;
								if (file_exists($imageFile)) {
								  echo $this->Html->image($myPath, array(
								  	'style' => 'height:195px;width:225px;margin:1px 225px',
								  	'id' => 'showThumbnail1'));
								}
								else echo '<img id="showThumbnail1" style="width:225px;margin:1px 225px"/>';
							}
							else echo '<img id="showThumbnail1" style="width:225px;margin:1px 225px"/>';
						?>		
				</li>
				<?php for($id = 2; $id <= 5; ++$id) { ?>
					<li class="product_edit_thumbnail" id="thumbnail_<?=$id?>">
							<span class="titleName"><label>Thumbnail <?=$id?></label></span>
							<?php 
								echo $this->Form->file('image_form'.$id ,array('class'=>'inputFile', 'onchange' => 'modify_image(this, "showThumbnail'.$id.'")'));
								echo $this->Form->error('image_form'.$id,array('class'=>'error'));
							?>
							<?php
								$image = isset($this->data['Product']['image'.$id])? $this->data['Product']['image'.$id] : '';
								echo $this->Form->hidden('image'.$id, array('value'=>$image));
							if ($image) {
								$rId = $id;
								$myPath = "posts/" . $this->data['Product']['image'.$id];
								$imageFile = IMAGES . $myPath;
								if (file_exists($imageFile)) {
								  echo $this->Html->image($myPath, array(
								  	'style' => 'height:195px;width:225px;margin:15px 225px',
								  	'id' => 'showThumbnail'.$id));
								}
								else echo '<img id="showThumbnail'.$id.'" style="width:225px;margin:15px 225px"/>';
							}
							else echo '<img id="showThumbnail'.$id.'" style="width:225px;margin:15px 225px"/>';
							?>		
					</li>
				<?php } ?>
				<li id="product_edit_show_more_thumbnail">
					<span class="titleName button_container" style="float:left">
						<a href="javascript:void(0)">Add more image</a>
					</span>
				</li>
				<li style="clear:both">
						<span class="titleName"><label>Description</label></span>
						<div class="editorBox">
								<?php
								echo $this->Form->textarea('description', array('id'=>'description'));
								echo $this->Form->error('description');
								?>
						</div>
				</li>
			</ul>
			<?=$this->Form->button(__('Save and publish', true), array('class' => 'btnYellow01 btn', 'type' => 'submit', 'style'=>'display:none', 'id'=>'save_publish','name'=>'savePublish')); ?>
			<div class="button_container" style="float:left;margin-top:15px">
				<a class="btnYellow01 btn" href="#" onclick="$('#save_publish').click(); return false;"><span class="btnBg">Save Product</span></a>
				<a href="<?=$this->webroot.'products/view/'.$id?>" class="btnYellow01 btn"><span class="btnBg">Cancel</span></a>
			</div>
</div>
</div>
</div>
<?php
echo $this->Form->end();
?>
<script>
CKEDITOR.replace( 'description', {height: 300});
CKEDITOR.on("instanceReady", function(){
    $('#cke_description').css('margin-left', '25.5%').css('margin-top', '-20px');
});
</script>
